package com.zrong.gamesdk.test.integration.thread;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransport;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 12-6-28
 * Time: 上午10:43
 * To change this template use File | Settings | File Templates.
 */
public class GameCommentThread implements Runnable {
    private String commentContent;
    private String serviceId;
    private Integer commentOrigin;
    private long userId;
    private long times;

    public GameCommentThread(String commentContent, String serviceId, String commentOrigin, long userId, long times) {
        this.commentContent = commentContent;
        this.serviceId = serviceId;
        this.commentOrigin = Integer.valueOf(commentOrigin);
        this.userId = userId;
        this.times = times;

    }

    private GameCommentClient.Client createGameCommentClient() throws Exception {
        TTransport transport = new THttpClient("http://localhost:8080/UserPartake/service/thrift/gameComment");
        TProtocol protocol = new TBinaryProtocol(transport);
        GameCommentClient.Client client = new GameCommentClient.Client(protocol);
        return client;
    }

    @Override
    public void run() {

        try {
            GameCommentClient.Client client = this.createGameCommentClient();
            for (long i = 0; i < times; i++) {
                GameComment gameComment = new GameComment();
                gameComment.setCommentContent(this.commentContent);
                gameComment.setCommentOrigin(this.commentOrigin);
                gameComment.setServiceId(this.serviceId);
                gameComment.setUserId(userId);
                client.saveGameComment(gameComment);
            }
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
